package com.yifeng.repo.controller.statemachine.fsm.order;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by daibing on 2024/2/15.
 */
@Getter
@AllArgsConstructor
public enum OrderStateEnum {
    WAITING_PAYMENT(0, "待付款"),
    WAITING_DELIVERY(1, "待发货"),
    WAITING_RECEIVE(2, "待收货"),
    FINISHED(3, "已完成"),
    CANCELLED(4, "已取消"),
    CLOSED(5, "已关闭"),
    ;

    @EnumValue
    @JsonValue
    private final Integer code;
    private final String name;

    private static final Map<Integer, OrderStateEnum> mappings = new HashMap<>(8);

    static {
        for (OrderStateEnum value : values()) {
            mappings.put(value.getCode(), value);
        }
    }

    public static OrderStateEnum resolve(Integer code) {
        return (code != null ? mappings.get(code) : null);
    }

}
